<form class="layui-form" action="" enctype=multipart/form-data>

    <div class="layui-form-item">
        <label class="layui-form-label">报警视频名称</label>
        <div class="layui-input-block">
            <input type="text" name="avidname" lay-verify="required" autocomplete="off" placeholder="请输入名称"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">报警视频URL</label>
        <div class="layui-input-block">
            <input name="avidurl" value="" type="hidden">
            <button type="button" class="layui-btn" id="avidurl" >
                <i class="layui-icon">&#xe67c;</i>上传视频
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">视频预览图URL</label>
        <div class="layui-input-block">
            <input name="skchimgurl" value="" type="hidden">
            <button type="button" class="layui-btn" id="skchimgurl" >
                <i class="layui-icon">&#xe67c;</i>上传预览图
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">报警视频录制时间</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="starttime" id="starttime">
        </div>
    </div>
<<<<<<< HEAD

=======
>>>>>>> 497bf4992b532a40a332ea7ff630269e26f27104
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(["jquery", "form", "upload","laydate","layer"], function () {
        var $ = layui.jquery
            , form = layui.form
            , upload = layui.upload
            ,laydate=layui.laydate
            ,layer=layui.layer;

        form.on('submit(demo1)', function (data) {//点击提交按钮
            $.ajax({
                url: "/alarmvideo/addAlarmvideo",
                data: data.field,
                dataType: "json",
                type: "post",
                success: function (msg) {
                    if (msg.code == 0) {
                        tableIns.reload({
                            page: {
                                curr: 1
                            }
                        });
                        layer.msg(msg.msg);//提示后台传过来的信息
                        layer.close(openIndex);//关闭当前弹出的窗体
                    } else {
                        layer.msg(msg.msg);//提示后台传过来的信息
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        //执行实例
        var uploadInst = upload.render({
            elem: '#avidurl' //绑定元素
            ,url: '/file/upload' //上传接口
            ,done: function(res){
                //上传完毕回调
                layui.msg(res.msg);
                $('input[name="avidurl"]').value=res.data;
            }
            ,error: function(){
                //请求异常回调
            }
        });
        var uploadInst = upload.render({
            elem: '#skchimgurl' //绑定元素
            ,url: '/file/upload' //上传接口
            ,done: function(res){
                layer.msg(res.msg);
                $('input[name="skchimgurl"]').value=res.data;
                //上传完毕回调
            }
            ,error: function(){
                //请求异常回调
            }
        });
        laydate.render({
            elem: '#starttime' //指定元素
        });
        form.render();
    });
</script>